﻿using System.Collections.Generic;

namespace RatingAuthor
{
  public struct GenresSet
  {
    private const int Size = 64;
    private readonly long _data;

    public GenresSet(IEnumerable<int> bits) 
      : this()
    {
      foreach (var bit in bits)
        _data |= (1 << bit);
    }

    public IEnumerable<string> Lookup(GenresLookup lookup)
    {
      var tester = 1;
      for (int i = 0; i < Size; i++, tester <<= 1)
        if ((_data & tester) != 0)
          yield return lookup[i];
    }

    public GenresSet(long data) 
      : this()
    {
      _data = data;
    }

    public bool this[int index]
    {
      get { return (_data & (1 << index)) != 0; }
    }
    public static implicit operator GenresSet(long data)
    {
      return new GenresSet(data);
    }
    public static implicit operator long(GenresSet set)
    {
      return set._data;
    }
  }
}